#!/usr/bin/python
#-*- coding: utf-8 -*-

import mysql.connector
import random

connect = mysql.connector.connect(user='arcra', password='@arcra;', host='bacchus.kmsc.or.kr', database='arcra')
cursor = connect.cursor()

mod_hash = {"Chest PA" : 0.05, "Abdomen Flat, Upright" : 1.1, "Abdominal Pelvic CT with contrast" : 25.0, "Brain CT without contrast" : 4.0, "Chest CT with contrast" : 6.0}
for i in range(990):
    print "%d start..." % (i),
    s = random.uniform(0.8, 1.2)
    pid = random.randint(1,18)
    hid = random.randint(1,4)
    study = random.sample(mod_hash.keys(), 1)
    sday = random.randint(1,31)
    stimeh = random.randint(0,23)
    stimem = random.randint(0,59)
    
    query = "INSERT INTO studies (pid, hid, dose, s_time, name) VALUES (%d, %d, %f, \"2012-12-%d %d:%d\", \"%s\")" % (pid, hid, mod_hash[study[0]] * s, sday, stimeh, stimem, study[0])
    cursor.execute(query)
    
    print "%d finish" % (i)
connect.commit()

query = "SELECT pid, hid, dose, s_time, name FROM studies"
cursor.execute(query)

for (rpid, rhid, rdose, rs_time, rname) in cursor:
    print rpid, rhid, rdose, rs_time, rname

cursor.close()
connect.close()